<template>
      <div>
         <!--:rules是给表达绑定校验规则-->
         <el-form :rules="rules" ref="loginForm" :model="loginForm" class="loginContainer">
             <h3 class="loginTiele">系统登录</h3>
             <!--这里的这一个prop属性是与data里面校验规则的rules里面的相对应的-->
             <el-form-item prop="userName">
               <el-input type="text" v-model="loginForm.userName" placeholder="请输入用户名"></el-input>
             </el-form-item>
             <el-form-item prop="password">
               <el-input type="text" v-model="loginForm.password" placeholder="请输入密码"></el-input>
             </el-form-item>
             <el-form-item prop="code">
               <el-input type="text" v-model="loginForm.code" placeholder="点击图片更换验证码" style="width: 250px;margin-right: 5px"></el-input>
               <img :src="captchaUrl">
             </el-form-item>
             <el-button type="primary" style="width: 100%" class="loginButton" @click="login">登录</el-button>
         </el-form>
      </div>
</template>

<script>
export default {
  name: "LoginView",
  data(){
    return{
      captchaUrl:"",
      loginForm:{
        userName:123,
        password:"root",
        code:''
      },
      rules:{
        userName:[{ required: true, message: '请输入用户名', trigger: 'blur' }], //增加校验规则,必填,失去焦点的时候触发,弹出提示信息请输入用户名
        password:[{ required: true, message: '请输入密码', trigger: 'blur' }], //增加校验规则,必填,失去焦点的时候触发,弹出提示信息请输入密码
        code:[{ required: true, message: '请输入验证码', trigger: 'blur' }] //增加校验规则,必填,失去焦点的时候触发,弹出提示信息请输入验证码
      }
    }
  },
  methods:{
    submitForm() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          this.$message.error('请输入所有条件');
          return false;
        }
      });
    }
  }
}
</script>

<style>
 .loginContainer{
   border-radius: 15px;
   background-clip: padding-box;
   margin: 180px  auto;
   width: 350px;
   padding: 15px 35px 15px 35px;
   background: #fff;
   border: 1px solid #eaeaea;
   box-shadow: 0 0 25px #cac6c6;
 }
 .loginTiele{
   margin: 0px auto 40px auto;
   text-align: center;
 }
 .loginButton{
   margin: 0px 0px 15px 0px;
 }

</style>